import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/home/main_page.dart';

class IdentityWidget extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return IdentityState();
  }

}

class IdentityState extends State{
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.fromLTRB(24, 24, 24, 12),
            alignment: Alignment.topLeft,
            child: Row(
              children: <Widget>[
                ConstrainedBox(
                    constraints: BoxConstraints(
                      maxHeight: 120,
                      maxWidth: 120,
                    ),
                    child: Image.network("https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=213017542,198580089&fm=26&gp=0.jpg",width: 120,height: 120,)
                ),
                Container(
                  alignment: Alignment.topCenter,
                  margin: EdgeInsets.fromLTRB(24, 0, 24, 0),
                  child: Text(
                    MainPage.username,
                    style: TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                )
              ],
            ),
          ),
          Container(child: Divider(height: 2,thickness: 1,),),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.fromLTRB(24, 6, 24, 6),
            child: MaterialButton(
              child: Text(
                  "切换账户",
                style: TextStyle(fontSize: 20,color: Colors.black45),
              ),
                onPressed: (){
                  showDialog(
                    context: context,
                    builder: (BuildContext context) =>
                        AlertDialog(
                          title: Text("注销登录"),
                          content: Text("确定注销登录"),
                          actions: <Widget>[
                            MaterialButton(
                              child :Text("取消",style: TextStyle(color: Colors.blue,fontSize: 16),),
                              onPressed: (){
                                Navigator.of(context).pop();
                              },
                            ),
                            MaterialButton(
                                child :Text("确定",style: TextStyle(color: Colors.red,fontSize: 16),),
                                onPressed: (){
                                  Navigator.pushNamedAndRemoveUntil(context, "First", (route)=> route == null);
                                },
                            ),

                          ],
                        )
                  );
                }),
          ),
          Container(child: Divider(height : 1,thickness: 1,),),
          Container(
            margin: EdgeInsets.fromLTRB(24, 6, 24, 6),
            child: MaterialButton(
                child: Text(
                  "退出登录",
                  style: TextStyle(fontSize: 20,color: Colors.red),
                ),
                onPressed: (){
                  showDialog(
                      context: context,
                      builder: (BuildContext context) =>
                          AlertDialog(
                            title: Text("退出登录"),
                            content: Text("确定退出登录"),
                            actions: <Widget>[
                              MaterialButton(
                                child :Text("取消",style: TextStyle(color: Colors.blue,fontSize: 16),),
                                onPressed: (){
                                  Navigator.of(context).pop();
                                },
                              ),
                              MaterialButton(
                                child :Text("确定",style: TextStyle(color: Colors.red,fontSize: 16),),
                                onPressed: (){
                                  showDialog(
                                      context: context,
                                      builder: (BuildContext context) =>
                                          AlertDialog(
                                            title: Text("删除数据"),
                                            content: Text("是否删除所有用户数据"),
                                            actions: <Widget>[
                                              MaterialButton(
                                                child :Text("取消",style: TextStyle(color: Colors.blue,fontSize: 16),),
                                                onPressed: (){
                                                  exit(0);
                                                },
                                              ),
                                              MaterialButton(
                                                child :Text("确定",style: TextStyle(color: Colors.red,fontSize: 16),),
                                                onPressed: (){
                                                  exit(0);
                                                },
                                              ),

                                            ],
                                          )
                                  );
                                },
                              ),

                            ],
                          )
                  );
                }
                ),
          ),
        ],
      ),
    );
  }

}